package com.ivideo.backend.base.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Project: ivideo-parent
 * @Name: Result
 * @Author: Jack_Li
 * @Date: 2024/5/20 13:51
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {

    private Integer code;
    private String message;
    private T data;
    private long timestamp;

    public static <T> Result<T> success(T data) {
        return new Result<T>(ResultCodeEnum.RC200.getCode(), ResultCodeEnum.RC200.getMessage(), data, System.currentTimeMillis());
    }

    public static <T> Result<T> success(T data, String message) {
        return new Result<T>(
                ResultCodeEnum.RC200.getCode(),
                message,
                data,
                System.currentTimeMillis()
        );
    }

    public static <T> Result<T> error(Integer code, String message) {
        return new Result<T>(code, message, null, System.currentTimeMillis());
    }

    public static <T> Result<T> error(ResultCodeEnum resultCodeEnum) {
        return new Result<T>(resultCodeEnum.getCode(), resultCodeEnum.getMessage(), null, System.currentTimeMillis());
    }

}
